﻿Public Class FormTaskList
    Dim objClsTask As New clsTask
    Dim objClsSysParam As New clsSysParam
    Dim dtTask As New DataTable
    Private Sub FormTaskList_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        checkAgvSwitch()
        initTask()
    End Sub

    Public Sub initTask()
        If btnAgvSwitch.Text.Equals("停用AGV") Then
            dtTask = objClsTask.SelectTask()
            dgvTask.AutoGenerateColumns = False
            dgvTask.DataSource = dtTask
        Else
            If dtTask.Rows.Count > 0 Then
                dtTask.Rows.Clear()
            End If
            dgvTask.DataSource = dtTask
        End If
    End Sub

    Private Sub checkAgvSwitch()
        Dim dt As DataTable = objClsSysParam.selectAgvSwitch()
        If dt.Rows.Count = 1 Then
            If dt.Rows(0)("param_value").ToString().Equals("1") Then
                btnAgvSwitch.Text = "停用AGV"
            Else
                btnAgvSwitch.Text = "启用AGV"
            End If
        End If
    End Sub

    Private Sub btnRefresh_Click(sender As Object, e As EventArgs) Handles btnRefresh.Click
        initTask()
    End Sub

    Private Sub btnTaskCancel_Click(sender As Object, e As EventArgs) Handles btnTaskCancel.Click
        If dgvTask.SelectedRows.Count > 0 Then
            Dim rtn As Integer = objClsTask.TaskCancel(dgvTask.SelectedRows(0).Cells("Colsys_id").Value.ToString())
            If rtn <> -2 Then
                MsgBox("取消成功")
                initTask()
            Else
                MsgBox("取消失败")
            End If
        Else
            MsgBox("请选择需要取消的行")
        End If
    End Sub

    Private Sub btnAgvSwitch_Click(sender As Object, e As EventArgs) Handles btnAgvSwitch.Click
        If btnAgvSwitch.Text.Equals("停用AGV") Then
            If MsgBox("确认要停用AGV吗？", vbYesNo, "提示") = vbYes Then
                If MsgBox("是否取消之前待创建的任务？", vbYesNo, "提示") = vbYes Then
                    Dim rtns As Integer = objClsTask.TaskCancel()
                    If rtns <> -2 Then
                        MsgBox("取消成功")
                        initTask()
                    Else
                        MsgBox("取消失败")
                    End If
                Else

                End If
                Dim rtn As Integer = objClsSysParam.Update("0", "agv_switch")
                If rtn <> -2 Then
                    btnAgvSwitch.Text = "启用AGV"
                    MsgBox("停用AGV成功")
                    initTask()
                Else
                    MsgBox("停用AGV失败")
                End If
            End If
        Else
            Dim rtn As Integer = objClsSysParam.Update("1", "agv_switch")
            If rtn <> -2 Then
                btnAgvSwitch.Text = "停用AGV"
                MsgBox("启用AGV成功")
                initTask()
            Else
                MsgBox("启用AGV失败")
            End If
        End If
        checkAgvSwitch()
    End Sub

    Private Sub btnTaskTransfer_Click(sender As Object, e As EventArgs) Handles btnTaskTransfer.Click
        If dgvTask.SelectedRows.Count > 0 Then
            Dim rtn As Integer = objClsTask.task_transfer(dgvTask.SelectedRows(0).Cells("Colsys_id").Value.ToString())
            If rtn <> -2 Then
                MsgBox("迁移成功")
                initTask()
            Else
                MsgBox("迁移失败")
            End If
        Else
            MsgBox("请选择需要迁移的行")
        End If
    End Sub
End Class

Public Class entity_task_record
    Public sys_id As String
    Public type As String
    Public prod_id As String
    Public status As String
    Public start_time As String
    Public end_time As String
    Public update_time As String
    Public tm As String
    Public lhj As String
    Public prod_spec_id As String
End Class

Public Class entity_task_step_record
    Public sys_id As String
    Public prio As String
    Public pick As String
    Public drop As String
    Public agv As String
    Public task_id As String
    Public status As String
    Public prod_id As String
    Public previous_id As String
    Public update_time As String
    Public lhj As String
    Public prod_spec_id As String
End Class
